package HandshakeJoin;

import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogBaseClient implements DBClient
{
    transient private static final Logger logger = LoggerFactory
            .getLogger(LogBaseClient.class);

    public static void initGlobal() {
        // TODO
    }

    private final String tableName;
    private final int numColumns;

    public LogBaseClient(final String tableName, final int numColumns) {
        this.tableName = tableName;
        this.numColumns = numColumns;
    }

    public boolean init() {
        // TODO
        return true;
    }

    public void close() {
        // TODO
    }

    public boolean materialize(Snapshot snapshot) {
        // TODO
        return true;
    }

    public List<ArrayList<Integer>> retrieveByTimestamp(long ts) {
        // TODO
        return dummy();
    }

    public List<ArrayList<Integer>> retrieveByTimestamp(long tsLower,
            long tsUpper) {
        // TODO
        return dummy();
    }

    public List<ArrayList<Integer>> retrieveByJoinKey(int val) {
        // TODO
        return dummy();
    }

    public List<ArrayList<Integer>> retrieveByJoinKey(int valLower, int valUpper) {
        // TODO
        return dummy();
    }

    /**
     * Delete this dummy function in the real implementation!
     */
    private List<ArrayList<Integer>> dummy() {
        return Lists.newLinkedList();
    }

    /**
     * Test client.
     */
    public static void main(String[] args) throws Exception {
        LogBaseClient.initGlobal();

        final int numColumns = 3;
        DBClient db = new LogBaseClient("test", numColumns);
        db.init();

        int[][] data = { { 1, 2, 3 }, { 1, 3, 4 }, { 2, 5, 3 }, { 3, 2, 6 },
                { 1, 3, 2 }, { 4, 5, 1 }, { 3, 7, 2 }, { 5, 4, 3 } };
        List<ArrayList<Integer>> records = Lists.newLinkedList();
        for (int i = 0; i < data.length; ++i) {
            records.add(Lists.newArrayList(Ints.asList(data[i])));
        }
        Snapshot snapshot = new Snapshot("test", records);

        db.materialize(snapshot);

        System.out.println("@@@ Test: Equal selection wrt Join key @@@");
        records = db.retrieveByJoinKey(1);
        for (ArrayList<Integer> record : records) {
            System.out.println(record);
        }

        System.out.println("@@@ Test: Range selection wrt Join key @@@");
        records = db.retrieveByJoinKey(2, 3);
        for (ArrayList<Integer> record : records) {
            System.out.println(record);
        }

        System.out.println("@@@ Test: Equal selection wrt Timestamp @@@");
        records = db.retrieveByTimestamp(snapshot.getTimeStamp());
        for (ArrayList<Integer> record : records) {
            System.out.println(record);
        }

        db.close();
    }
}